package vip.xumy.core.pojo;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import lombok.Data;
import vip.xumy.core.pojo.com.Cache;

/**	All rights reserved
 *	author:mengyxu
 *	date:2019年12月13日
 */

@Data
@SuppressWarnings("all")
public class BufferResult {
	
	private String key;
	private boolean effective;
	private String loseTime;
	private Object value;
	
	public BufferResult(String key, Cache cache) {
		this.key = key;
		this.effective = !Cache.isEmpty(cache);
		this.loseTime = cache.getLoseTime();
		this.value = cache.getValue();
		if(value instanceof Map) {
			Map map = (Map) value;
			Set keySet = map.keySet();
			if(!keySet.isEmpty() && keySet.toArray()[0] instanceof Integer) {
				Map<String, Object> newMap = new HashMap<>();
				for (Object mapKey : keySet) {
					newMap.put(mapKey.toString(), map.get(mapKey));
				}
				this.value = newMap;
			}
		}
	}
	
}
